import {getAccountInfo, getToken, setAccountInfo, setToken} from "@/utils/auth";

const account = {
    //数据仓库
    state() {
        return {
            token: getToken(),
            accountInfo: JSON.parse(getAccountInfo()),
            permissions: []
        }
    }, mutations: {
        SET_TOKEN: (state, token) => {
            state.token = token
            setToken(token) //更新cookie中的token
        }, SET_ACCOUNT_INFO: (state, accountInfo) => {
            state.accountInfo = JSON.parse(accountInfo)
            setAccountInfo(accountInfo) //更新cookie中的
        }, SET_PERMISSION: (state, permission) => {
            state.permissions = permission
        }
    },
    actions: {}
}

export default account
